<?php

namespace fanletter\library;

/**
 * 
 * Connects to the database
 * @author Evan
 *
 */
class SQLConnection
{
	private $dbserver = '';
	private $dbbase = '';
	private $dbusername = '';
	private $dbpassword = '';
	
	private $dbReference = null;
	static private $instance = null;
	
	private function __construct()
	{
		/*
		 * TODO: We have to include the settings here
		 */
		
		try 
		{
			$this->dbReference = new PDOSafe('mysql:host='.$this->dbserver.';dbname='.$this->dbbase, $this->dbusername, $this->dbpassword);
			$this->dbReference->exec('SET CHARACTER SET utf8');
		}
		catch (PDOException $e) 
		{
   			print "Error!: " . $e->getMessage() . "<br/>";
  			die();
		}
				
	}
	
	/**
	 * Returns the Instance of SQLConnection
	 * @return SQLConnection
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = new self;
		}
		return self::$instance;
	}
	/**
	 * Returns the DB Reference
	 * @return PDOSafe 
	 */
	public function getDBReference()
	{
		return $this->dbReference;
	}
	
}

?>